<%@ page import="java.util.List" %>
<%@ page import="com.hnluchuan.staff.model.Education" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.hnluchuan.staff.dto.EducationDTO" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>

<%@include file="/common/head.jsp" %>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                    	<form role="form" class="form-inline" id="query-form" method="post" action="${ctx }/admin/education/list" >
                    		<!-- 查询开始 -->
							<%
								Integer type=(Integer)request.getAttribute("type");
								EducationDTO educationDTO=(EducationDTO) request.getAttribute("n");
								if(1==type&&educationDTO==null)
								{
							%>
                            <div class="form-group">

                                <label for="query-employee" class="sr-only2">员工ID</label>
                                	<input type="text" id="query-employee-id" name="employee.id" value="${query.employee.id }" class="form-control">
				                 	<input type="hidden" class="form-control" id="employee-name" name="employee.id" value="${query.employee.id }"
				                 		onclick="bring({
										                 	url:'${ctx}/admin/employee/search',
										                 	name: 'id',
										                 	idInput: 'employee-id',
										                 	nameInput: 'employee-name'
										                 	})" />	
                            </div>
                            <div class="form-group">
									<button class="btn btn-primary btn-sm" type="submit"><i class="fa fa-search"></i>&nbsp;查询</button>
                            </div>
                            <!-- 查询结束 -->
							<%
								}
							%>
                        </form>
                    
						<div>
							<p>
		                        <button type="button" class="btn btn-sm btn-outline btn-primary" onclick="add()"><i class="fa fa-plus"></i> 新增</button>
		                        <button type="button" class="btn btn-sm btn-outline btn-info " onclick="edit()"><i class="fa fa-paste"></i> 修改</button>
								<%
									Integer types=(Integer)request.getAttribute("type");
									EducationDTO educationDTOs=(EducationDTO) request.getAttribute("n");
									if(1==types&&educationDTOs==null)
									{
								%>
		                        <button type="button" class="btn btn-sm btn-outline btn-danger" onclick="del()">删除</button>
								<%
									}
								%>
		                        <button type="button" class="btn btn-sm btn-outline btn-info " onclick="reOpen()"><i class="fa fa-refresh"></i> 刷新</button>
		                    </p>
						</div>
						<table id="table" data-toggle="table" data-striped="true" data-click-to-select="true" data-mobile-responsive="true">
                                    <thead>
                                        <tr>
                                            <th data-field="_state" data-checkbox="true"></th>

											<c:if test="${type==1}">
												<th data-field="id" data-visible="false">ID</th>
												<th data-field="employee">员工ID</th>
											</c:if>

                                            <th data-field="start">学习起始时间</th>
                                            <th data-field="end">学习结束时间</th>
                                            <th data-field="major">专业</th>
                                            <th data-field="record">学历</th>
                                            <th data-field="certificate">证书</th>
                                        </tr>
                                    </thead>
							<tbody>

							<%--<c:if test="${type==1}">--%>
								<c:forEach items="${list }" var="n" varStatus="idx">
									<c:if test="${type==1}">
										<tr data-index="${idx.index }" data-id="${n.id }">
									</c:if>

										<td class="bs-checkbox">
											<input data-index="0" name="btSelectItem" type="checkbox">
										</td>
									<c:if test="${type==1}">

										<td style="">${n.id }</td>
										<td style="">${n.employee.id}</td>
									</c:if>
										<td style="">
											<fmt:formatDate value="${n.start }" pattern="yyyy-MM-dd"/>
										</td>
										<td style="">
											<fmt:formatDate value="${n.end }" pattern="yyyy-MM-dd"/>
										</td>
										<td style="">${n.major }</td>
										<td style="">
											<c:if test="${n.record ==1}">
												大专
											</c:if>
											<c:if test="${n.record==2 }">
												本科
											</c:if>
											<c:if test="${n.record==3}">
												研究生
											</c:if>

										</td>
										<td style="">${n.certificate }</td>
									</tr>
								</c:forEach>

							<%--</c:if>--%>
							<%
//							List<Education> list=(ArrayList<Education>)request.getAttribute("list");
							%>

							</tbody>
						</table>
                   
						<%@include file="/common/page.jsp" %>

					</div>
                </div>
            </div>
        </div>
    </div>

<%@include file="/common/foot.jsp" %>
<script>
function add() {
    layer.open({
        type: 2,
        skin: 'layui-layer-rim', //加上边框
        area: [layer_default_width, layer_default_height], //宽高
        content: "${ctx}/admin/education/detail",
        btn: ['确定', '取消'],
        yes: function(index, layero){ //或者使用btn1
            var detailForm = layer.getChildFrame('form', index);
            console.log(detailForm);
            //验证学习起始的时间
            var start = $('#start',detailForm).val();
            if (!!!start){alert('请输入学习起始时间.'+start);return false;}
			// 验证学习结束的时间
			var end = $('#end',detailForm).val();
			if (!!!end){alert('请输入学习结束时间.'+end);return false}
            var major = $('#major', detailForm).val();
            if(!!!major){alert('请输入专业.'+major);return false;}
            // var record = $('#record', detailForm).val();
            // if(!!!record){alert('请输入学历.');return false;}
            var certificate = $('#certificate', detailForm).val();
            if(!!!certificate){alert('请输入证书.');return false;}
            // var recordReg = /^[0-9]*$/;
            // if(!recordReg.test(record)) {
            //      alert('学历请输入数字.');
            //     return false;
            // }

            detailForm.ajaxSubmit({
                success: function(data) {
                    if (isSuccess(data)) {
                        layer.close(index);
                        reload();
                    } else {
                    }
                }
            });
        }, cancel: function(index){ //或者使用btn2
            //按钮【按钮二】的回调
        }
    });
    //k.layer.add("${ctx}/admin/education/detail");
}

function edit() {
    var selections = $('#table').bootstrapTable('getAllSelections');
	if (selections.length != 1) {
        // 点击详情的时候进行页面提示
        alert("请选择对应的记录：");
		error2(k.msg.requireOne);
		return;
	}
	var id = selections[0].id;
	k.layer.edit("${ctx}/admin/education/detail?id=" + id);
}
var page = "${page.page}";
function reload() {
	page_submit(page);
}

function del() {
    var selections = $('#table').bootstrapTable('getAllSelections');
    if (selections.length < 1) {
        error('请选择要删除的记录');
        return;
    }
    var ids = new Array();
    for (var i = 0; i < selections.length; i++) {
        ids.push(selections[i].id);
    }
    $.ajax({
        url: "${ctx}/admin/education/delete",
        data: {
            ids: ids.join(',')
        },
        success: function(data) {
            if (isSuccess(data)) {
                reload();
            }
        }
    });
}
paging('pagination', ${page.totalPages}, ${page.page});

</script>
</body>
</html>